<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="java.util.List"%>
<%@ page import="com.aimee.entity.Lunbo" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公告栏管理</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<style>

</style>
<body>
<%
    List<Lunbo> list = (List) request.getAttribute("adverpage");
%>
    <div class="layui-tab">
        <ul class="layui-tab-title">
          <li class="layui-this">全部公告</li>
          <li>创建公告</li>
        </ul>
        <div class="layui-tab-content">
          <div class="layui-tab-item layui-show">
            <table class="layui-table">
                <thead>
                  <tr>
                      <th>序号</th>
                      <th>文件名</th>
                      <th>大小</th>
                      <th>操作</th>
                  </tr>
                </thead>
                <tbody id="demoList2">
                <c:forEach items="${adverpage}" var="adver">
                    <tr>
                        <td>${adver.advertise_id}</td>
                        <td>${adver.advertise_address}</td>
                        <td>${adver.advertise_size}</td>
                        <td><button class="layui-btn btndel"  dataid='${adver.advertise_id}'>删除</button></td>
                    </tr>
                </c:forEach>
                </tbody>
              </table>
          </div>
          <div class="layui-tab-item">
            <div class="layui-upload"> 
                <div class="layui-upload-list">
                    <form action="../admin/lunbo?m=upload" method="post" enctype="multipart/form-data">
                  <table class="layui-table">
                    <thead>
                      <tr>
                          <th>文件名</th>
                      <th>大小</th>
                      <th>状态</th>
                      <th>操作</th>
                    </tr></thead>
                    <tbody id="demoList"></tbody>
                  </table>

                      <label  class="layui-btn">选择文件
                          <input type="file" name="picfile"  id="choose" multiple="multiple" style="opacity:0;width: 10px">
                      </label>
<%--                        <input type="file" name="picfile"  id="choose" multiple="multiple" style="">--%>
                        <button type="submit" class="layui-btn" >开始上传公告</button>
                    </form>
                </div>

              </div>  

          </div>
        </div>
      </div>
    <!-- *********************************** -->       
   
</body>
<script src="../layui/layui.js"></script>
<script>
    layui.use(['element','upload'], function(){
  var $ = layui.jquery
  ,element = layui.element//Tab的切换功能，切换事件监听等，需要依赖element模块
      ,upload = layui.upload;

        //所有删除 加事件
        $(".btndel").click(function(){
            var advertise_id=$(this).attr("dataid");
            layer.confirm('您确定删除该用户？',{btn:['确定','取消'],title:"提示"},function(index){
                console.log("已删除--》"+advertise_id);
                location.href="http://localhost:8080/OnlineExam/admin/lunbo?m=del&advertise_id="+advertise_id;
                layer.close(index);
            });
        });

  
    //多文件列表示例
    var demoListView = $('#demoList')
  ,uploadListIns = upload.render({
    elem: '#choose' //选择文件的按钮
    ,url: '../admin/lunbo?m=upload' //后台处理文件长传的方法
    ,accept: 'file'
    ,multiple: true
    ,auto: false
    // ,bindAction: '#testListAction'
    ,choose: function(obj){   
      var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
      //读取本地文件
      obj.preview(function(index, file, result){
        var tr = $(['<tr id="upload-'+ index +'">'
          ,'<td>'+ file.name +'</td>'
          ,'<td>'+ (file.size/1024).toFixed(1) +'kb</td>'
          ,'<td>等待上传</td>'
          ,'<td>'
            ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
          ,'</td>'
        ,'</tr>'].join(''));
        
        //单个重传
        tr.find('.demo-reload').on('click', function(){
          obj.upload(index, file);
        });
        
        //删除
        tr.find('.demo-delete').on('click', function(){
          delete files[index]; //删除对应的文件
          tr.remove();
          uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
        });
        
        demoListView.append(tr);
      });
    }
    ,done: function(res, index, upload){
      if(res.files.file){ //上传成功
        var tr = demoListView.find('tr#upload-'+ index)
        ,tds = tr.children();
        tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
        tds.eq(3).html(''); //清空操作
        return delete this.files[index]; //删除文件队列已经上传成功的文件
      }
      this.error(index, upload);
    }
    ,error: function(index, upload){
      var tr = demoListView.find('tr#upload-'+ index)
      ,tds = tr.children();
      tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
      tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
    }
  });
});
</script>
</html>